#pragma once


extern "C"
{
#include "avcodec.h"
#include "avformat.h"
}

class CMediaFrame
{
public:
	CMediaFrame();
	virtual ~CMediaFrame(){};


	BOOL GetTime(LONGLONG& llStart, LONGLONG &llStop);
	BOOL SetTime(LONGLONG llStart, LONGLONG llStop);

	VOID SetEOS(BOOL fEos = TRUE);
	BOOL GetEOS();

	virtual EMediaType GetType();
	virtual BOOL Copy(IMediaSample* pSample, AM_MEDIA_TYPE* pmt);		

private:
	LONGLONG m_llStart, m_llStop;
	BOOL     m_fEOS;



};


class CVideoFrame : public CMediaFrame
{
public:
	CVideoFrame();
	~CVideoFrame();

	EMediaType GetType();
	BOOL GetFormat(PixelFormat &fmt, int& w, int& h);	
	BOOL SetFormat(PixelFormat fmt, int w, int h);	

	AVFrame* GetAVFrame();	
	BOOL Copy(IMediaSample* pSample, AM_MEDIA_TYPE* pmt);		
	BOOL ChangeUVOrder();

private:
	AVFrame* alloc_picture(PixelFormat fmt, int w,  int h);
	VOID free_picture();

	AVFrame* m_pFrame;
	PixelFormat m_fmt;
	int m_dataSize;
	int m_w;
	int m_h;	
	uint8_t* m_pBufferUvChange;
	
};


class CAudioFrame : public CMediaFrame
{

public:
	CAudioFrame();
	~CAudioFrame();

	EMediaType GetType();
	BOOL GetFormat(int &Channels, int& sampleRate);			
	BOOL SetFormat(int Channels, int sampleRate);

	BOOL SetSampleCount(int sc);
	int  GetSampleCount();
	BOOL InitDefaultBuffer();
	
	int    GetDataSize(){return m_nDataSize;};
	void   SetDataSize(int size);
	short* GetDataPointer(){return m_pData;};
	
	BOOL Copy(IMediaSample* pSample, AM_MEDIA_TYPE* pmt);	

private:
	int m_nChannels;	
	int m_nSamplesPerSec;
	int m_nDataSize;
	int m_nBufferSize;
	short* m_pData;	
	int m_nSampleCount;
};


